<?php
use Pinenut\Form;

class IndexAction extends \Pinenut\Action
{
	protected static $layout = "#layout";

	protected function run()
	{
		$formId = 'formId';
		$formConfig = \FormConfig::get();

		$form = new Form($this->request->getSessionId(), $formId, $formConfig);

		if ($this->request->isPost() && $this->request->isAjax()) {
			$form->process($this->request->params(), true);
			// вынести в хелпер
			$this->response->content =  $form->render();
			$this->response->noRender(true);
			return;


		} else if ($this->request->isPost() && !$this->request->isAjax()) {
			if ($form->process($this->request->params())) {
				$form->flush();
				$this->redirect('/');
			}
		}

		$this->response->form = $form;
	}
}